package demo.practice.bucket;

public class P287 {
    public static void main(String[] args) {
        P287 p287= new P287();
        p287.findDuplicate(new int[]{1,3,4,2,2});
    }
    public int findDuplicate(int[] nums) {

            int[]bucket= new int[nums.length];
            for(int i :nums){
                bucket[i]++;
                if(bucket[i]>1)
                    return i;
            }

            return -1;
    }
}
